<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目 - 豆是不吃豆豉</title><meta name="Description" content="Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能"><meta property="og:title" content="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目" />
<meta property="og:description" content="Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://dou-chi.gitee.io/jenkins-auto-test/" />
<meta property="og:image" content="https://dou-chi.gitee.io/logo.png"/>
<meta property="article:published_time" content="2021-01-15T10:21:20+08:00" />
<meta property="article:modified_time" content="2021-01-15T10:21:20+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://dou-chi.gitee.io/logo.png"/>

<meta name="twitter:title" content="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目"/>
<meta name="twitter:description" content="Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能"/>
<meta name="application-name" content="豆是不吃豆豉">
<meta name="apple-mobile-web-app-title" content="豆是不吃豆豉"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://dou-chi.gitee.io/jenkins-auto-test/" /><link rel="prev" href="https://dou-chi.gitee.io/kettle-paging/" /><link rel="next" href="https://dou-chi.gitee.io/docker-monitor/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/dou-chi.gitee.io\/jenkins-auto-test\/"
        },"genre": "posts","keywords": "Jenkins, Docker","wordcount":  2029 ,
        "url": "https:\/\/dou-chi.gitee.io\/jenkins-auto-test\/","datePublished": "2021-01-15T10:21:20+08:00","dateModified": "2021-01-15T10:21:20+08:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "豆是不吃豆豉"
            },"description": "Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能"
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('dark' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'dark' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="https://github.com/dou-chi" rel="noopener noreffer" target="_blank"> github </a><a class="menu-item" href="https://gitee.com/dou-chi" rel="noopener noreffer" target="_blank"> gitee </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="https://github.com/dou-chi" title="" rel="noopener noreffer" target="_blank">github</a><a class="menu-item" href="https://gitee.com/dou-chi" title="" rel="noopener noreffer" target="_blank">gitee</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content always-active" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>豆是不吃豆豉</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/jenkins/"><i class="far fa-folder fa-fw"></i>Jenkins</a>&nbsp;<a href="/categories/docker/"><i class="far fa-folder fa-fw"></i>Docker</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-01-15">2021-01-15</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 2029 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 5 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#痛点">痛点</a></li>
        <li><a href="#jenkins-安装部署">Jenkins 安装部署</a></li>
        <li><a href="#vue项目dockerfile">Vue项目Dockerfile</a></li>
        <li><a href="#springboot-dockerfile">SpringBoot Dockerfile</a></li>
        <li><a href="#jenkins构建项目">Jenkins构建项目</a>
          <ul>
            <li><a href="#配置git源码">配置GIt源码</a></li>
            <li><a href="#配置构建vue">配置构建Vue</a></li>
            <li><a href="#配置构建springboot">配置构建SpringBoot</a></li>
            <li><a href="#立即构建">立即构建</a></li>
          </ul>
        </li>
        <li><a href="#总结">总结</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><style>
    img {margin: 0 auto; display: block;}
</style>
<h2 id="痛点">痛点</h2>
<p>由于公司的人手不够，导致了其中一个项目的<code>前端、后端</code>全都由我一个人开发。项目架构采用的是<code>Vue</code> + <code>SpringBoot</code>前后端分离的架构，每次都要手动打包部署到测试环境给测试人员测试功能，一个人，这工作量实在伤不起，所以想到使用<code>Jenkins</code>自动打包部署到测试环境，极大减轻负担。</p>
<h2 id="jenkins-安装部署">Jenkins 安装部署</h2>
<p>作为一个可扩展的自动化服务器，Jenkins 可以用作简单的 CI 服务器，或者变成任何项目的持续交付中心。</p>
<p>官方Docker仓库网址：<a href="https://hub.docker.com/r/jenkins/jenkins" target="_blank" rel="noopener noreffer">https://hub.docker.com/r/jenkins/jenkins</a></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">
// 拉取jenkins镜像
docker pull jenkins/jenkins:2.275-centos7
// 创建文件夹，提供给jenkins映射
mkdir -p /usr/local/jenkins/home
// 启动
docker run -d <span class="se">\
</span><span class="se"></span>-p 8080:8080 <span class="se">\
</span><span class="se"></span>-p 50000:50000 <span class="se">\
</span><span class="se"></span>-v /usr/local/jenkins/home:/var/jenkins_home <span class="se">\
</span><span class="se"></span>--name jenkins <span class="se">\
</span><span class="se"></span>jenkins/jenkins:2.275-centos7

// <span class="o">==============</span><span class="nv">命令说明</span><span class="o">==================</span> /
// -d后台运行
docker run -d <span class="se">\
</span><span class="se"></span>// 映射端口
-p 8080:8080 <span class="se">\
</span><span class="se"></span>-p 50000:50000 <span class="se">\
</span><span class="se"></span>// 挂载 jenkins 工作目录到宿主机
-v /usr/local/jenkins/home:/var/jenkins_home <span class="se">\
</span><span class="se"></span>--name jenkins <span class="se">\
</span><span class="se"></span>jenkins/jenkins:2.275-centos7

// 如果启动报错，查看日志
docker logs jenkins

// 有可能缺少权限，增加权限
chown -R 1000:1000 /usr/local/jenkins/home/
</code></pre></td></tr></table>
</div>
</div><p>浏览器输入对应的地址<code>http://192.168.3.11:8080/</code>，需要等一会儿。访问不到先查看端口是否打开，<code>centos7</code>打开端口命令</p>
<ul>
<li>查看已经开放的端口： <code>firewall-cmd --list-port</code></li>
<li>打开端口：<code>firewall-cmd --zone=public --add-port=8080/tcp --permanent </code></li>
<li>关闭端口：<code>firewall-cmd --zone=public --remove-port=8080/tcp --permanent</code></li>
<li>重启防火墙： <code>firewall-cmd --reload</code></li>
</ul>
<p>登录</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDq1Kg.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDq1Kg.png, https://s3.ax1x.com/2021/01/16/sDq1Kg.png 1.5x, https://s3.ax1x.com/2021/01/16/sDq1Kg.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDq1Kg.png"
        title="sDq1Kg.png" /></p>
<p>初始密码，可是使用<code>docker logs jenkins</code>查看，或者到挂载的宿主机查看。</p>
<p><a href="https://imgchr.com/i/sDqWRK" target="_blank" rel="noopener noreffer"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDqWRK.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDqWRK.png, https://s3.ax1x.com/2021/01/16/sDqWRK.png 1.5x, https://s3.ax1x.com/2021/01/16/sDqWRK.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDqWRK.png"
        title="sDqWRK.png" /></a></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDq5se.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDq5se.png, https://s3.ax1x.com/2021/01/16/sDq5se.png 1.5x, https://s3.ax1x.com/2021/01/16/sDq5se.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDq5se.png"
        title="sDq5se.png" /></p>
<p>安装默认插件。安装完成后设置默认用户</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDL6Og.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDL6Og.png, https://s3.ax1x.com/2021/01/16/sDL6Og.png 1.5x, https://s3.ax1x.com/2021/01/16/sDL6Og.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDL6Og.png"
        title="sDL6Og.png" />需要用到的插件<code>maven</code>和<code>NodeJs</code>,在<code>系统管理-》插件管理-可选插件搜索Maven、NodeJs、Publish Over SSH</code>，选择安装，再回到首页<code>系统管理-》全局插件配置-配置Maven、NodeJs和Publish Over SSH</code>。</p>
<ul>
<li>maven插件: 构建SpringBoot</li>
<li>NodeJs插件: 构建Vue</li>
<li>Publish Over SSH插件:连接宿主机执行<code>build</code>等命令</li>
</ul>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDL4f0.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDL4f0.png, https://s3.ax1x.com/2021/01/16/sDL4f0.png 1.5x, https://s3.ax1x.com/2021/01/16/sDL4f0.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDL4f0.png"
        title="sDL4f0.png" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDzkWR.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDzkWR.png, https://s3.ax1x.com/2021/01/16/sDzkWR.png 1.5x, https://s3.ax1x.com/2021/01/16/sDzkWR.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDzkWR.png"
        title="jenkin-node" /></p>
<p>系统配置中配置远程用户名密码
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDLL79.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDLL79.png, https://s3.ax1x.com/2021/01/16/sDLL79.png 1.5x, https://s3.ax1x.com/2021/01/16/sDLL79.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDLL79.png"
        title="sDLL79.png" /></p>
<p>由于项目存在隐私问题，这里我们使用<a href="https://gitee.com/y_project/RuoYi-Vue" target="_blank" rel="noopener noreffer">ruoyi-vue</a>来做演示，我们在<code>gitee</code>上先将<code>ruoyi-vue</code>fork到我们自己的仓库。ruoyi目前还没有使用docker,没有Dockerfile,需要我们自己构建。</p>
<h2 id="vue项目dockerfile">Vue项目Dockerfile</h2>
<p><code>Vue</code>打包后生成dist目录，需要依赖于<code>Nginx</code>运行，增加一个<code>.dockerignore</code>和<code>Dockerfile</code>文件。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> nginx:alpine</span><span class="err">
</span><span class="err"></span><span class="k">VOLUME</span><span class="s"> /tmp</span><span class="err">
</span><span class="err"></span><span class="k">ENV</span> LANG en_US.UTF-8<span class="err">
</span><span class="err"></span><span class="k">RUN</span> <span class="nb">echo</span> -e <span class="s2">&#34;server {  \n\
</span><span class="s2">            listen       80; \n\
</span><span class="s2">            server_name  localhost; \n\
</span><span class="s2">            location / { \n\
</span><span class="s2">              root   /var/www/html; \n\
</span><span class="s2">              try_files \$uri \$uri/ /index.html; \n\
</span><span class="s2">              index  index.html index.htm; \n\
</span><span class="s2">            } \n\
</span><span class="s2">            location /prod-api/ { \n\
</span><span class="s2">              proxy_set_header Host \$http_host; \
</span><span class="s2">              proxy_set_header X-Real-IP \$remote_addr; \n\
</span><span class="s2">              proxy_set_header REMOTE-HOST \$remote_addr; \n\
</span><span class="s2">              proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; \n\
</span><span class="s2">              proxy_pass http://192.168.3.13:8088/; \n\
</span><span class="s2">            } \n\
</span><span class="s2">          }&#34;</span> &gt; /etc/nginx/conf.d/default.conf <span class="se">\
</span><span class="se"></span>    <span class="o">&amp;&amp;</span>  mkdir  -p  /var/www <span class="se">\
</span><span class="se"></span>    <span class="o">&amp;&amp;</span>  mkdir -p /var/www/html<span class="err">
</span><span class="err"></span><span class="k">ADD</span> dist/ /var/www/html/<span class="err">
</span><span class="err"></span><span class="k">EXPOSE</span><span class="s"> 80</span><span class="err">
</span><span class="err"></span><span class="k">EXPOSE</span><span class="s"> 443</span><span class="err">
</span><span class="err">
</span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">doc
public
src
.dockerignore
.editorconfig
.eslintignore
.gitattributes
.gitignore
.prettierrc
babel.config.js
Dockerfile
idea.config.js
LICENSE
package.json
package-lock.json
README.md
vue.config.js
yarn
yarn.lock
yarn-error.log
.idea
.svn
node_modules
</code></pre></td></tr></table>
</div>
</div><h2 id="springboot-dockerfile">SpringBoot Dockerfile</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dockerfile" data-lang="dockerfile"><span class="k">FROM</span><span class="s"> anapsix/alpine-java:8_server-jre_unlimited</span><span class="err">
</span><span class="err"></span><span class="c"># 设置时区</span><span class="err">
</span><span class="err"></span><span class="k">RUN</span> ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime<span class="err">
</span><span class="err">
</span><span class="err"></span><span class="k">WORKDIR</span><span class="s"> /ruoyi</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="k">EXPOSE</span><span class="s"> 8088</span><span class="err">
</span><span class="err">
</span><span class="err"></span><span class="k">ADD</span> ./target/ruoyi-admin3.3.0.jar app.jar<span class="err">
</span><span class="err">
</span><span class="err"></span><span class="k">ENTRYPOINT</span> <span class="p">[</span><span class="s2">&#34;java&#34;</span><span class="p">,</span> <span class="s2">&#34;-jar&#34;</span><span class="p">,</span> <span class="s2">&#34;app.jar&#34;</span><span class="p">]</span><span class="err">
</span><span class="err"></span>// 预留位置给容器增加java运行参数<span class="err">
</span><span class="err"></span><span class="k">CMD</span> <span class="p">[</span><span class="s2">&#34;sleep 1s;&#34;</span><span class="p">]</span><span class="err">
</span></code></pre></td></tr></table>
</div>
</div><h2 id="jenkins构建项目">Jenkins构建项目</h2>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/sDLjt1.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/sDLjt1.png, https://s3.ax1x.com/2021/01/16/sDLjt1.png 1.5x, https://s3.ax1x.com/2021/01/16/sDLjt1.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/sDLjt1.png"
        title="jenkins" /></p>
<p><code>创建任务-&gt;</code>构建一个自由风格的软件项目`</p>
<h3 id="配置git源码">配置GIt源码</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srSjbT.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srSjbT.png, https://s3.ax1x.com/2021/01/16/srSjbT.png 1.5x, https://s3.ax1x.com/2021/01/16/srSjbT.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srSjbT.png"
        title="git" /></p>
<h3 id="配置构建vue">配置构建Vue</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srSzaF.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srSzaF.png, https://s3.ax1x.com/2021/01/16/srSzaF.png 1.5x, https://s3.ax1x.com/2021/01/16/srSzaF.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srSzaF.png"
        title="Node" /></p>
<p>执行<code>shell</code>打包<code>Vue</code>项目，生成<code>dist</code>文件夹。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srSXrV.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srSXrV.png, https://s3.ax1x.com/2021/01/16/srSXrV.png 1.5x, https://s3.ax1x.com/2021/01/16/srSXrV.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srSXrV.png"
        title="Vue打包" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">// 进入到Vue根路径
<span class="nb">cd</span> ruoyi-ui
// 方便调试
<span class="nb">pwd</span>
npm -version
// 安装依赖，指定淘宝镜像
npm install --registry<span class="o">=</span>https://registry.npm.taobao.org
// 删除旧版本打包
rm -rf ./dist/*
// 打包
npm run build:prod
</code></pre></td></tr></table>
</div>
</div><p>远程执行<code>shell</code>打包成<code>docker镜像</code>，并运行镜像</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srSxVU.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srSxVU.png, https://s3.ax1x.com/2021/01/16/srSxVU.png 1.5x, https://s3.ax1x.com/2021/01/16/srSxVU.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srSxVU.png"
        title="docker打包" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">// 进入到jenkins工作目录（docker运行时挂载的）
<span class="nb">cd</span> /usr/local/jenkins/home/workspace/ruoyi-vue/ruoyi-ui
// 停止旧版本容器
sudo docker stop ruoyi-front
// 删除旧版本容器
sudo docker rm ruoyi-front
// 停止旧版本镜像
sudo docker rmi ruoyi-front、
// docker构建容器，如果需要保留旧版本的话，可以根据git版本或者根据时间生成镜像，
//如 sudo docker build -t ruoyi-front:20210114 .
sudo docker build -t ruoyi-front .
// 运行容器
docker run -d -p 3000:80 --name ruoyi-front ruoyi-front
</code></pre></td></tr></table>
</div>
</div><h3 id="配置构建springboot">配置构建SpringBoot</h3>
<p>使用<code>maven</code>打包</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srSOK0.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srSOK0.png, https://s3.ax1x.com/2021/01/16/srSOK0.png 1.5x, https://s3.ax1x.com/2021/01/16/srSOK0.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srSOK0.png"
        title="Maven" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">// jenkins 会自动拼接上mvn
clean install -D.skip.test<span class="o">=</span><span class="nb">true</span>
</code></pre></td></tr></table>
</div>
</div><p>远程执行<code>shell</code>打包成<code>docker镜像</code>，并运行镜像</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srpS54.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srpS54.png, https://s3.ax1x.com/2021/01/16/srpS54.png 1.5x, https://s3.ax1x.com/2021/01/16/srpS54.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srpS54.png"
        title="docker springboot" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">// 进入到jenkins工作目录（docker运行时挂载的）
<span class="nb">cd</span>  /usr/local/jenkins/home/workspace/ruoyi-vue/ruoyi-admin
// 停止旧版本容器
sudo docker stop ruoyi-back
// 删除旧版本容器
sudo docker rm ruoyi-back
// 停止旧版本镜像
sudo docker rmi ruoyi-back
// docker构建容器，如果需要保留旧版本的话，可以根据git版本或者根据时间生成镜像，
//如 sudo docker build -t ruoyi-back:20210114 .
sudo docker build -t ruoyi-back .
// 运行容器
docker run -d -p 8088:8080 --name ruoyi-back ruoyi-back
</code></pre></td></tr></table>
</div>
</div><h3 id="立即构建">立即构建</h3>
<p>返回项目主页，点击立即构建，在左下角，可以查看实时日志。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srCxVf.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srCxVf.png, https://s3.ax1x.com/2021/01/16/srCxVf.png 1.5x, https://s3.ax1x.com/2021/01/16/srCxVf.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srCxVf.png"
        title="jenkins-build" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srPixs.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srPixs.png, https://s3.ax1x.com/2021/01/16/srPixs.png 1.5x, https://s3.ax1x.com/2021/01/16/srPixs.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srPixs.png"
        title="jenkins-console" /></p>
<p>当构建完成之后，我们执行<code>docker images</code>和<code>docker ps</code>查看镜像和正在运行的容器。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srPEq0.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srPEq0.png, https://s3.ax1x.com/2021/01/16/srPEq0.png 1.5x, https://s3.ax1x.com/2021/01/16/srPEq0.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srPEq0.png"
        title="jenkins-docker" /></p>
<p>我们开启相应的端口，访问<code>Vue</code>映射出来的端口<code>3000</code>。已经成功构建，前后台都可以成功访问。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/16/srPyeP.png"
        data-srcset="https://s3.ax1x.com/2021/01/16/srPyeP.png, https://s3.ax1x.com/2021/01/16/srPyeP.png 1.5x, https://s3.ax1x.com/2021/01/16/srPyeP.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/16/srPyeP.png"
        title="ruoyi" /></p>
<h2 id="总结">总结</h2>
<p>使用了<code>Jenkins</code>减少了我很多重复性的工作，我们还可以采用<code>GitHook</code>的方式，在每次提交代码之后，自动构建并打包到测试环境。现在我们采用的是前后端分开<code>docker build</code>的方式，我们还可以使用<code>Docker Compose</code>的方式一次打包运行，减少项目<code>Jenkins</code>构建的步骤，并且还可以使用<code>Docker Compose</code>统一管理。</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-01-15</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/jenkins-auto-test/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目" data-hashtags="Jenkins,Docker"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-hashtag="Jenkins"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目" data-description="Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目" data-description="Jenkins Docker 自动打包Vue项目和SpringBoot项目运行，用于给测试测试功能"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://dou-chi.gitee.io/jenkins-auto-test/" data-title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/jenkins/">Jenkins</a>,&nbsp;<a href="/tags/docker/">docker</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/kettle-paging/" class="prev" rel="prev" title="Kettle循环分页导入数据"><i class="fas fa-angle-left fa-fw"></i>Kettle循环分页导入数据</a>
            <a href="/docker-monitor/" class="next" rel="next" title="Docker容器可视化和主机可视化监控">Docker容器可视化和主机可视化监控<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.3">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2019 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">豆是不吃豆豉</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><link rel="stylesheet" href="/lib/cookieconsent/cookieconsent.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript" src="/lib/cookieconsent/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":100},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
